package tau_sadna.tau_map;

import android.util.Log;

public class Communication {

	static boolean downloadConfig(String fname) {
		Connection con = new Connection();
		if (con.errState) {
			Log.v("Communication", "failed to establish connection");
			return false;
		}
		String config = con.getConfig(); // blocking
		if (config == null) {
			Log.v("Communication", "failed to recv config file");
			return false;
		}
		con.close();
		
		int succ = FileIO.write(config, fname);
		if (succ != 0) {
			Log.v("Communication", "failed to write config to file");
			return false;
		}
		Log.v("Communication", "recieving config and writing to file "+fname+" successful");
		return true;
	}

	static boolean downloadItem(String itemName, String fname) {
		Connection con = new Connection();
		if (con.errState) {
			Log.v("Communication", "failed to establish connection");
			return false;
		}
		String layer = con.getLayer(itemName); // blocking
		if (layer == null) {
			Log.v("Communication", "failed to recv layer: "+itemName);
			return false;
		}
		con.close();
		
		int succ = FileIO.write(layer, fname);
		if (succ != 0) {
			Log.v("Communication", "failed to write layer: "+itemName+" to file");
			return false;
		}
		Log.v("Communication", "recieving layer: "+itemName+" and writing to file "+fname+" successful");
		return true;

	}

}
